<!--<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title>Generation du XML</title>
    </head>
    <body> -->
	
<?php
		include 'header.html';

 //       $prepaXML_serial_slash = $_POST['generer'];
//        $prepaXML_serial_deslash = html_entity_decode($prepaXML_serial_slash);
//        $tableauxml = unserialize($prepaXML_serial_slash);
 //       echo "<br>". $prepaXML_serial_slash ."<br><br>";
		
		
		$tableaugeneral_serial_slash = $_POST['generer'];
        var_dump($tableaugeneral_serial_slash);
        $tableaugeneral_serial_deslash = htmlspecialchars_decode($tableaugeneral_serial_slash);
        var_dump($tableaugeneral_serial_deslash);
        $tableaugeneral = unserialize($tableaugeneral_serial_deslash);		
		var_dump($tableaugeneral);
		
		/// traitement decoupage tableau general < -- CONTINUER ICI Jeudi 28 aout après-midi
		
		
		while (list($action) = each($tableaugeneral)) {
			echo "action = " . $action . "<br>";
			
			while (list($numero) = each($tableaugeneral[$action])) {
				echo " - > numero = " . $numero . "<br>";
				echo " - - > code = " . $tableaugeneral[$action][$numero][0] . "<br>";
				echo " - - > nom = " . $tableaugeneral[$action][$numero][1] . "<br>";
				echo " - - > prenom = " . $tableaugeneral[$action][$numero][2] . "<br>";
				echo " - - > genre = " . $tableaugeneral[$action][$numero][3] . "<br>";
				echo " - - > classe = " . $tableaugeneral[$action][$numero][4] . "<br>";
				echo " --------- <br>";
			}
			echo " ========= <br>";
		}
		
		
		
		
		
		
		
		

$xml= new DOMDocument("1.0", "ISO-8859-1"); // creation d'une chaine XML en utilisant le DOM
        
        $racine = $xml->createElement("Users");
        $racine = $xml->appendChild($racine);

        
            $user = $xml->createElement("User");
            $user->setAttribute("Id", "AB001"); /// id_eleve ou id_prof = $tableaucsv[$i][0]
            $user->setAttribute("Language", "fr"); /// par déft en français
            $user->setAttribute("Action", "Insert"); /// insert ou Delete ou Ignore ou Update = $action
            $user = $racine->appendChild($user);

                    $active = $xml->createElement("Active"); 
                    $active = $user->appendChild($active);
                    $t_active = $xml->createTextNode("true"); /// par deft true
                    $t_active = $active->appendChild($t_active);

                    $role = $xml->createElement("Role");
                    $role->setAttribute("Action", "Assign"); /// par deft Assign
                    $role->setAttribute("Id", "PROF"); /// par deft PROF
                    $role->setAttribute("Type", "Global");
                    $role = $user->appendChild($role);
                    $t_role = $xml->createTextNode("PROF");
                    $t_role = $role->appendChild($t_role);

                    $role = $xml->createElement("Role");
                    $role->setAttribute("Action", "Assign"); /// par deft Assign
                    $role->setAttribute("Id", "PROF_1PGA"); /// role PROF_classe
                    $role->setAttribute("Type", "Global");
                    $role = $user->appendChild($role);
                    $t_role = $xml->createTextNode("PROF_1PGA");
                    $t_role = $role->appendChild($t_role);
                    
                    $role = $xml->createElement("Role");
                    $role->setAttribute("Action", "Assign"); /// par deft Assign
                    $role->setAttribute("Id", "il_grp_member_7278"); /// role membre groupe = $tableaucsv[$i][6]
                    $role->setAttribute("Type", "Local");
                    $role = $user->appendChild($role);
                    $t_role = $xml->createTextNode("il_grp_member_7278");
                    $t_role = $role->appendChild($t_role);
                    
                    $login = $xml->createElement("Login");
                    $login = $user->appendChild($login);
                    $t_login = $xml->createTextNode("login1"); /// login_eleve ou login_prof
                    $t_login = $login->appendChild($t_login); /// correspond à ...
                    
                    $mdp = $xml->createElement("Password");
                    $mdp->setAttribute("Type", "ILIAS3");
                    $mdp = $user->appendChild($mdp);
                    $t_mdp = $xml->createTextNode("motdepasse1"); /// mdp_eleve ou mdp_prof
                    $t_mdp = $mdp->appendChild($t_mdp); /// correspond à ...
                    
                    $genre = $xml->createElement("Gender");
                    $genre = $user->appendChild($genre);
                    $t_genre = $xml->createTextNode("F"); /// genre = M ou F  = $tableaucsv[$i][3]
                    $t_genre = $genre->appendChild($t_genre);
                    
                    $prenom = $xml->createElement("Firstname");
                    $prenom = $user->appendChild($prenom);
                    $t_prenom = $xml->createTextNode("prenom1"); /// prenom_eleve ou prenom_prof = $tableaucsv[$i][2]
                    $t_prenom = $prenom->appendChild($t_prenom);
                    
                    $nom = $xml->createElement("Lastname");
                    $nom = $user->appendChild($nom);
                    $t_nom = $xml->createTextNode("nom1"); /// nom_eleve ou nom_prof = $tableaucsv[$i][1]
                    $t_nom = $nom->appendChild($t_nom);
                    
                    $mail = $xml->createElement("Email");
                    $mail = $user->appendChild($mail);
                    $t_mail = $xml->createTextNode("toto1@gmail.fr"); /// mail_eleve ou mail_prof
                    $t_mail = $mail->appendChild($t_mail); /// correspond à ...
                    
          
        $fichierxml = chemin("chemin_xml") . "\\" . "role_" .  @date("Y-M-d_H-i-s") . ".xml"; /// nom du fichier XML de sortie 
        
        $xml->save($fichierxml); /// création du fichier XML de sortie contenant 
        echo "<br>Le fichier $fichierxml a &eacute;t&eacute; cr&eacute;&eacute;<br><br>"; // la chaine xml construite avec DOMDocument
        ?>

        <input type="button" name="retour" id="retour" 
                   onclick="document.location.href = 'index.php'" 
                   value="Retourner à Accueil">           

    </body>
</html>        